using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using CoachingOrganizer.Logic.Models.Common;
using CoachingOrganizer.iOS.Helpers;
using CoachingOrganizer.iOS.DataSources;

namespace CoachingOrganizer.iOS.Controllers
{
    public partial class SupplyGoalDetailsViewController : UIViewController
    {
        private readonly GoalModel _model;

        public SupplyGoalDetailsViewController(IntPtr handle)
            : base(handle)
        {
            _model = ((GoalDetailsViewController)ParentViewController).Model;
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            UIHelper.RegisterCellClass(ToolsView, ToolsDataSource.CellIdentifer);
            ToolsView.Source = new ToolsDataSource(ToolsView, this, _model);
			ChooseToolView.DataSource = new ChooseToolDataSource(ChooseToolView, this, _model);
            InitModel();
        }

        private async void InitModel()
        {
            using (System.Threading.CancellationTokenSource cancellation = new System.Threading.CancellationTokenSource())
                await _model.LoadToolsAsync(cancellation.Token);
        }

        partial void AddNewTool(NSObject sender)
        {
            int toolNumber = ChooseToolView.SelectedRowInComponent(0);
            switch (toolNumber)
            {
                case 0:
                    _model.AddNewMoodLevel();
                    break;
                case 1:
                    _model.AddNewEmotionsPack();
                    break;
                case 2:
                    _model.AddNewMoneyCalculation();
                    break;
                default:
                    throw new System.NotImplementedException();
            }
        }

        partial void GoBack(NSObject sender)
        {
            ParentViewController.DismissViewController(true, null);
        }
    }
}